
{mfdeclre.i}

{pxmaint.i}

PROCEDURE ShiftData :

   define parameter buffer fp_mstr     for fp_mstr.
   define input parameter latest    as date   no-undo.
   
   define buffer fp for fp_mstr.

   define variable i as integer.
   
   find first fp no-lock where fp.fp_part = fp_mstr.fp_part and fp.fp_site = fp_mstr.fp_site 
       and fp.fp_start = latest no-error.
       
   if not available fp then return error {&APP-ERROR-RESULT}.
   
    if (weekday(latest) + fp_mstr.fp_start - latest) <= 7 then do:
        do i = (weekday(latest) + fp_mstr.fp_start - latest) to 21:
            fp_mstr.fp_days[i] = fp.fp_days[i].
        end.

        do i = 3 to 12:
            fp_mstr.fp_weeks[i] = fp.fp_weeks[i].
        end.
        
    end.
    else if (weekday(latest) + fp_mstr.fp_start - latest) <= 14 then do: 

        do i = (weekday(latest) + fp_mstr.fp_start - latest) - 7 to 14:
            fp_mstr.fp_days[i] = fp.fp_days[i + 7].
        end.

        do i = 15 to 20 :
            fp_mstr.fp_days[i] = integer(fp.fp_weeks[3] / 7).
        end.


        fp_mstr.fp_days[21] = fp.fp_weeks[ 3] - fp_mstr.fp_days[15] - fp_mstr.fp_days[16] - fp_mstr.fp_days[17]
                                              - fp_mstr.fp_days[18] - fp_mstr.fp_days[19] - fp_mstr.fp_days[20].

        do i = 4 to 12 :
            fp_mstr.fp_weeks[i - 1] = fp.fp_weeks[i].
        end.

    end.

    fp_mstr.fp_weeks[1] = fp_mstr.fp_days[ 8] + fp_mstr.fp_days[ 9] + fp_mstr.fp_days[10] + fp_mstr.fp_days[11] + 
                          fp_mstr.fp_days[12] + fp_mstr.fp_days[13] + fp_mstr.fp_days[14].
    fp_mstr.fp_weeks[2] = fp_mstr.fp_days[15] + fp_mstr.fp_days[16] + fp_mstr.fp_days[17] + fp_mstr.fp_days[18] + 
                          fp_mstr.fp_days[19] + fp_mstr.fp_days[20] + fp_mstr.fp_days[21].
                          
   return {&SUCCESS-RESULT}.

END PROCEDURE.

